<?php
namespace App\Http\Controllers\Api\Mall;

use App\Http\Controllers\Controller;
use App\Models\Mall\Goods;
use App\Models\Mall\GoodsType;
use Illuminate\Http\Request;

class GoodsController extends Controller 
{
	public function all( Request $request )
	{
		$type = $request->input('t', 0);

		if ( $type > 0 ) {
			$query = GoodsType::find($type)->goods()->orderBy('id', 'desc')->where('sort', '<>', -1);
		} else {
			$query = Goods::orderBy('sort', 'desc')->where('sort', '<>', -1);
		}
		$goods = $query->paginate(10);

		return response()->json(['code' => 1000, 'data' => $goods])->withCallback($request->input('callback'));
	}

	public function detail( Request $request )
	{
		$goods = Goods::findOrFail( $request->input('id') );
		
		return response()->json(['code' => 1000, 'data' => $goods])->withCallback($request->input('callback'));
	}
}